import { cached } from '@/utils'
import request from '@/utils/request'

export const ENUM_MAP = {
  applyTypeIn: 'ApplyTypeInEnum', // 入库类型
  applyTypeOut: 'ApplyTypeOutEnum', // 出库类型
  auditStatus: 'AuditStatusEnum', // 审核状态
  changeStatus: 'ChangeStatusEnum', // 变动状态
  changeType: 'ChangeTypeEnum', // 变动类型
  inoutEnum: 'InOutEnum', // 进出库类型
  stockStatus: 'StockStatusEnum', // 库存状态
  storeInStatus: 'StoreInStatusEnum', // 入库状态
  storeOutStatus: 'StoreOutStatusEnum', // 出库状态

  storeInWholeStatus: 'StoreInWholeStatusEnum' // 入库状态
}

/**
 * 获取后台枚举类型字典值
 * @param {枚举字典值} name
 * @returns
 */
export const getEnumDict = cached((name) => {
  return request({
    url: `/dictionary/${name}`,
    method: 'GET'
  })
})

const _STORE_IN_STATUS = {
  0: 'primary',
  1: 'success',
  9: 'danger'

}

export const storeInStatusTag = (val) => _STORE_IN_STATUS[val]
const _STORE_IN_WHOLE_STATUS = {
  0: 'primary',
  1: 'warning',
  2: 'success'
}

export async function getStoreInWholeStatus() {
  const { data } = await getEnumDict(ENUM_MAP.storeInWholeStatus)
  return data
}
export const storeInWholeStatusTag = val => _STORE_IN_WHOLE_STATUS[val]

